//
//  CameraGunListController.m
//  Runone
//
//  Created by runone01 on 16/8/11.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "CameraGunDetailListController.h"
#import "CameraGunDetailListCell.h"
#import "DeviceBaseInfo.h"
#import "CameraDetailController.h"
#import "RequestHelper.h"
#import "MJExtension.h"
#import "SVProgressHUD.h"
#import "UIImageView+WebCache.h"
#import "BoardDetailListCell.h"


@interface CameraGunDetailListController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, strong) NSMutableArray *upCameraArray;  //上行摄像枪
@property (nonatomic, strong) NSMutableArray *downCameraArray;//下行摄像枪
// ******************************* -主线上行- *******************************
@property (nonatomic, strong) NSMutableArray *mainUpCameraArray;//主线上行摄像枪
@property (nonatomic, strong) NSMutableArray *mainDownCameraArray;//主线下行摄像枪

// ******************************* -北连接线上行- *******************************
@property (nonatomic, strong) NSMutableArray *northUpCameraArray;//主线上行摄像枪
@property (nonatomic, strong) NSMutableArray *northDownCameraArray;//主线下行摄像枪

// ******************************* -南连接线上行- *******************************
@property (nonatomic, strong) NSMutableArray *southUpCameraArray;//主线上行摄像枪
@property (nonatomic, strong) NSMutableArray *southDownCameraArray;//主线下行摄像枪

@property (nonatomic, strong) NSMutableArray *passCameraArray; //传递过去的数组
@end
static NSString *const cellId =@"cell";
@implementation CameraGunDetailListController {
    
    UITableView *CameraTableView;
}

#pragma   ------------- 摄像枪列表


- (void)viewDidLoad {
    [super viewDidLoad];
   // UIImageView *imageV = [uivi];
    
    UILabel *label      = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
    label.text          = @"摄像枪列表";
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor     = [UIColor whiteColor];
    self.navigationItem.titleView = label;
    
    self.view.backgroundColor=[UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    CameraTableView                 = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64) style:UITableViewStylePlain];
    CameraTableView.bounces         = NO;
    CameraTableView.separatorColor  = [UIColor lightGrayColor];
    CameraTableView.backgroundColor = [UIColor clearColor];
    CameraTableView.delegate        = self;
    CameraTableView.dataSource      = self;
//    CameraTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [CameraTableView registerNib:[UINib nibWithNibName:@"BoardDetailListCell" bundle:nil] forCellReuseIdentifier:cellId];
    [self.view addSubview:CameraTableView];
}
- (void)viewWillAppear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = NO;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.contentArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BoardDetailListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    static NSString *cellId = @"cell";
    if (!cell) {
        cell = [[BoardDetailListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        //cell.selectionStyle    = UITableViewCellSelectionStyleNone;
    }
    [cell setHighlighted:NO];
    DeviceBaseInfo *deviceBaseInfo = self.contentArray[indexPath.row];

    //广乐特殊的要求，只能写死
    if ([_currentRoadModel.RoadUID isEqualToString:@"8dd13d88-cb02-4471-876b-1dfe39419ee6"]) {
        cell.pileNoLabel.text  = [NSString stringWithFormat:@"%@+%ld",deviceBaseInfo.PileNo,(long)deviceBaseInfo.PileDistance];
    } else {
        NSString *LStr       = @"L";
        NSString *LKStr      = [LStr stringByAppendingString:deviceBaseInfo.PileNo];
        cell.pileNoLabel.text  = [NSString stringWithFormat:@"%@+%ld",LKStr,(long)deviceBaseInfo.PileDistance];
    }
    
    cell.derectionLabel.text     =  deviceBaseInfo.DirectionName;
    
//        NSString *s=@"Bearer ";
//        NSString *strone;
//        NSUserDefaults*userDefults=[[NSUserDefaults alloc]init];
//        NSString*token=[userDefults objectForKey:@"AccessToken"];
//        [userDefults synchronize];
//    
//        SDWebImageDownloader *sdmanager = [SDWebImageManager sharedManager].imageDownloader;
//        if (token!=nil) {
//            
//            strone=[s stringByAppendingString:token];
//            [sdmanager setValue:strone forHTTPHeaderField:@"Authorization"];
//        }
//
    
    NSLog(@"图片URL%@",_currentRoadModel.RoadPicUrl);
//    NSString * str = _currentRoadModel.RoadPicUrl;
    [cell.userIconImage sd_setImageWithURL:[_currentRoadModel.RoadPicUrl mj_url] ];
    

    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CameraDetailController *vc     = [[CameraDetailController alloc] init];
    DeviceBaseInfo *deviceBaseInfo = self.contentArray[indexPath.row];
    vc.deviceBaseInfo              = deviceBaseInfo;
    vc.currentRoadModel            = _currentRoadModel;
    vc.roadType                    = _roadType;
    
    [self.navigationController pushViewController:vc animated:YES];
}
@end
